home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / uuenc < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  1.6 KB  |  70 lines

  1. #!/bin/ksh
  2. # @(#) uuenc.ksh 1.0 93/09/18
  3. # 93/09/18 john h. dubois iii (john@armory.com)
  4.  
  5. alias istrue="test 0 -ne"
  6. alias isfalse="test 0 -eq"
  7.  
  8. name=${0##*/}
  9. Usage="Usage: $name [-hf] <filename> ..."
  10. typeset -i force=0
  11.  
  12. while getopts :hf opt; do
  13.     case $opt in
  14.     h)
  15.     echo \
  16. "$name: uuencode files.
  17. $Usage
  18. For each filename given, $name uuencodes the file, using the final
  19. component of the file's path as the stored filename in the uuencoded
  20. archive and, with a .u appended, as the name to store the archive in.
  21. Example: 
  22. $name /tmp/foo
  23. The file /tmp/foo is uuencoded, with \"foo\" stored as the name to uudecode
  24. the file into, and the output is stored in a file in the current directory
  25. with the name \"foo.u\".
  26. Options:
  27. -f: Normally, if the file the output would be stored in already exists,
  28.     it is not overwritten and an error message is printed.  If -f (force)
  29.     is given, it is silently overwritten.
  30. -h: Print this help."
  31.     exit 0
  32.     ;;
  33.     f)
  34.     force=1
  35.     ;;
  36.     +?)
  37.     print -u2 "$name: options should not be preceded by a '+'."
  38.     exit 1
  39.     ;;
  40.     :) 
  41.     print -r -u2 -- \
  42.     "$name: Option '$OPTARG' requires a value.  Use -h for help."
  43.     exit 1
  44.     ;;
  45.     ?) 
  46.     print -u2 "$name: $OPTARG: bad option.  Use -h for help."
  47.     exit 1
  48.     ;;
  49.     esac
  50. done
  51.  
  52. # remove args that were options
  53. let OPTIND=OPTIND-1
  54. shift $OPTIND
  55.  
  56. if [ $# -lt 1 ]; then
  57.     print -u2 "$Usage\nUse -h for help."
  58.     exit
  59. fi
  60.  
  61. for file; do
  62.     tail=${file##*/}
  63.     out="$tail.u"
  64.     if isfalse force && [ -a "$out" ]; then
  65.     print -u2 "$name: $out: file exists.  Use -f to overwrite."
  66.     else
  67.     uuencode $file $tail > $out
  68.     fi
  69. done
  70.